@extends('admin.common.main')
@section('css')
<style>
</style>
@endsection
@section('cnt')
<div class="x-body">
    @include('admin.common.validate')
    @include('admin.common.msg')
    <form class="layui-form" action="{{ route('admin.user.store') }}" method="post" id="form-member-add">
        {{ csrf_field() }}
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>账号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="username" name="username"
                       autocomplete="off" class="layui-input" value="{{ old('username') }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="truename" class="layui-form-label">
                <span class="x-red">*</span>姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="truename" name="truename"
                       autocomplete="off" class="layui-input" value="{{ old('truename') }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span class="x-red">*</span>密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="password" name="password"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                6到16个字符
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
                <span class="x-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="password_confirmation" name="password_confirmation"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                <span class="x-red">*</span>手机
            </label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="phone"
                       autocomplete="off" class="layui-input" value="{{ old('phone') }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>角色</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" lay-skin="primary" title="先生" value="先生" checked="">
                <input type="radio" name="sex" lay-skin="primary" title="女士" value="女士">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_email" class="layui-form-label">
                <span class="x-red"></span>邮箱
            </label>
            <div class="layui-input-inline">
                <input type="email" id="email" name="email"
                       autocomplete="off" class="layui-input" value="{{ old('email') }}">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" type="submit">
                添加用户
            </button>
        </div>
    </form>
</div>
@endsection
@section('js')
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script>
    $("#form-member-add").validate({
        //规则
        rules:{
            //表单元素名称
            username:{
                required:true
            },
            truename:{
                required: true
            },
            password:{
                required:true
            },
            phone:{
                phone:true
            },
            email:{
                email:true
            },
            password_confirmation:{
                equalTo: '#password'
            },
        },
        messages:{
            username:"请输入用户名",
            truename:"请输入姓名",
            password:"请输入密码",
            password_confirmation:"两次输入的密码不一致",
        },
        onkeyup:false,
        success:"valid",
        submitHandler:function (form) {
            console.log(form)
            form.submit();
        }
    });



    //自定义验证规则
    jQuery.validator.addMethod("phone", function (value, element) {
        var reg1 = /^\+86-1[3-9]\d{9}$/;
        var reg2 = /^1[3-9]\d{9}$/;
        var ret = reg1.test(value) || reg2.test(value);
        return this.optional(element) || ret;
    }, "请输入正确的手机号码");


</script>
@endsection